<?php

$dir = "upload";
//print_r(glob("*.*"));
/*
if ($handle = opendir('./upload')) {
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != "..") {
            echo "$file\n";
        }
    }
    closedir($handle);
}
*/
$files = glob("$dir/*.*");
foreach ($files as $filename){
	$sOrg = basename("$filename");
	$sStart = 0;
	$sEnd = strpos($sOrg, ".");
	echo substr($sOrg, $sStart, $sEnd);
}

/* 字符串操作
$var = 'ABCDEFGH:/MNRPQR/';
echo "Original: $var<br />\n";
echo substr_replace($var, 'bob', 0, 0)."<br />\n";
echo substr_replace($var, '', 10, -1);

/*

这是是glob的实现
function glob($pattern, $flags)
{
  $path = preg_split(
     '#(?<=\A|[\\\\/])((?>[^\\\\/*?]*)[*?](?>[^\\\\/]*))(?=\Z|[\\\\/])#',
     $pattern, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY
   );

  foreach ($path as &$n)
   if (preg_match('/[*?]/', $n))
   {
     $re = '';
     for ($i = 0, $l = strlen($n); $i < $l; $i++)
       switch($n{$i})
       {
         case '*': $re .= '.*'; break;
         case '?': $re .= '.'; break;
         default: $re .= sprintf('\x%02x', ord($n{$i}));
       }
     $n = array(0, "/^$re$/i");
   }
   else
     $n = array(1, $n);

  $res = array();
  iglob_DFS($path, $flags, '', 0, $res);
  if (!($flags & GLOB_NOSORT))
   sort($res);

  return $res;
}
function iglob_DFS($path, $flags, $parent, $lvl, &$res)
{
  $depth = count($path) - 1;

  if (($lvl < $depth) && $path[$lvl][0])
   $parent .= $path[$lvl++][1];

  $files = array();
  if ($path[$lvl][0])
   $files[] = $path[$lvl][1];
  else
   if ($d = @opendir(($parent == '') ? '.' : $parent))
   {
     while (($n = readdir($d)) !== false)
       if ($n != '.' && $n != '..')
         $files[] = $n;
     closedir($d);
   }

  foreach ($files as $f)
   if ($path[$lvl][0] || preg_match($path[$lvl][1], $f))
   {
     $fullpath = $parent.$f;
     if ($lvl == $depth)
     {
       if (!($flags & GLOB_ONLYDIR) || is_dir($fullpath))
         $res[] = $fullpath;
     }
     else
       iglob_DFS($path, $flags, $fullpath, $lvl + 1, $res);
   }
}
齐萌(songlv)(66944555) 22:46:24
<?php
if(!(function_exists('glob')))
{function glob($pattern)
 {#get pathname (everything up until the last / or \)
  $path=$output=null;
  if(PHP_OS=='WIN32')
   $slash='\\';
  else
   $slash='/';
  $lastpos=strrpos($pattern,$slash);
  if(!($lastpos===false))
  {$path=substr($pattern,0,-$lastpos-1); #negative length means take from the right
   $pattern=substr($pattern,$lastpos);
  }
  else
  {#no dir info, use current dir
   $path=getcwd();
  }
  $handle=@ opendir($path);
  if($handle===false)
   return false;
  while($dir=readdir($handle))
  {if(pattern_match($pattern,$dir))
   $output[]=$dir;
  }
  closedir($handle);
  if(is_array($output))
   return $output;
  return false;
 }

 function pattern_match($pattern,$string)
 {#basically prepare a regular expression
  $out=null;
  $chunks=explode(';',$pattern);
  foreach($chunks as $pattern)
  {$escape=array('$','^','.','{','}',
                 '(',')','[',']','|');
   while(strpos($pattern,'**')!==false)
   $pattern=str_replace('**','*',$pattern);
   foreach($escape as $probe)
   $pattern=str_replace($probe,"\\$probe",$pattern);
   $pattern=str_replace('?*','*',
             str_replace('*?','*',
             str_replace('*',".*",
               str_replace('?','.{1,1}',$pattern))));
   $out[]=$pattern;
  }
  if(count($out)==1)
   return(eregi("^$out[0]$",$string));
  else
   foreach($out as $tester)
   if(eregi("^$tester$",$string))
     return true;
   return false;
 }
}
?>

*/

?>